package com.sk.bilibili.config;

import com.sk.bilibili.interceptor.CORSInterceptor;
import com.sk.bilibili.other.MemberArgumentResolver;
import com.sk.bilibili.utils.BSessionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author 邵康
 * @date 2021/12/4 10:49
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
//    @Autowired
//    private MemberArgumentResolver memberArgumentResolver;
//    @Override
//    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
//        resolvers.add(memberArgumentResolver);
//    }

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new CORSInterceptor());
//    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedHeaders("*")
                .allowedMethods("GET","POST","DELETE","PUT")
                .allowCredentials(true)
                .exposedHeaders(BSessionUtils.B_SESSION_ID)
                .maxAge(3600)
                .allowedOrigins("*");
    }

}
